import requests
from aip import AipFace

from config import *
from baidu_aip_utils import *

# 百度AIP接口
client = AipFace(BAIDU_AIP_APP_ID, BAIDU_AIP_API_KEY, BAIDU_AIP_SECRET_KEY)


"""待匹配的图片数据"""
image_urls = []

for page in range(1, 10):
    # 切换分页
    POST_DATA_ZHENAI["page"] = page
    response = requests.post('https://www.zhenai.com/api/search/getConditionData.do',
                             headers=HEADERS_ZHENAI, cookies=COOKIES_ZHENAI,
                             data=POST_DATA_ZHENAI)
    print("response code:", response.status_code, "data:", response.text)
    meizi_data = response.json()

    # 个人照片，数据层级：/data/list/0/avatarURL
    for meizi in meizi_data.get("data").get("list"):
        image_urls.append(http_image_format(meizi.get("avatarURL")))


""" 调用人脸比对 """
if __name__ == '__main__':
    if image_urls:
        for meizi_image_url in image_urls:
            # 调用人脸比对
            images = [
                image_file_format('data/ashuang.jpg'),
                http_image_format(meizi_image_url)
            ]
            result_json = client.match(images)
            print(result_json)
